package com.iflytek.sbd.demo.springflowtest;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

/**
 * @program: springbootdemo
 * @description:
 * @author: 陈英俊
 * @create: 2021-12-23 10:11
 */
@Component
@ConditionalOnProperty(
        prefix = "sbd",
        name = {"logPrint.open"},
        havingValue = "true"
)
public class MyBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        // 此处的bean需要返回, 不然逻辑就有问题了
        if (beanName.equals("apple")) {
            System.out.println("执行   BeanPostProcessor.postProcessBeforeInitialization方法");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (beanName.equals("apple")) {
            System.out.println("执行   BeanPostProcessor.postProcessAfterInitialization方法");
        }
        return bean;
    }
}
